// gui/GuiSelectableText.h

#ifndef _GUI_GuiSelectableText_H_
#define _GUI_GuiSelectableText_H_

#ifndef _CORE_std_H_
#include <core/std.h>
#endif

#ifndef _GUI_GuiSelectable_H_
#include "GuiSelectable.h"
#endif

#ifndef _GUI_GuiTextItem_H_
#include "GuiTextItem.h"
#endif

#ifndef _GUI_GuiHotSpotRect_H_
#include "GuiHotSpotRect.h"
#endif

namespace FONT
{
	class BMFont;
};


namespace GUI
{

class GuiSelectableText : public GuiSelectable
{
public:

	GuiSelectableText();

	virtual TypeId		GetTypeId() const {
		return s_TypeId;
	}
	static TypeId		GetStaticTypeId() {
		return s_TypeId;
	}

	void				SetupGuiSelectableText(wchar_t * pText, FONT::BMFont * pFont);

	// Accessors

	virtual void		SetActive(bool bActive);

	virtual void		SetSelectable(bool bSelectable);
	virtual void		SetHighlightable(bool bHighlightable);

	const GuiTextItem &	GetTextItem() const {
		return m_TextItem;
	}

	// APIs
	virtual bool		OnHighlight(bool bHighlighted);

	virtual void		Render( IRenderingEngine * pRenderer );

protected:

	virtual	void		UpdateVisual();

	virtual void		UpdateHotSpot();

private:

	static TypeId		s_TypeId;

	GuiHotSpotRect		m_HotSpot;
	GuiTextItem			m_TextItem;
};

inline GuiSelectableText::GuiSelectableText()
{
	GetFrame().AttachFrame( &m_TextItem.GetFrame() );
	SetHotSpot( &m_HotSpot );
}

inline void GuiSelectableText::SetupGuiSelectableText(wchar_t * pText, FONT::BMFont * pFont)
{
	m_TextItem.SetupGuiTextItem(pText, pFont);
	UpdateHotSpot();

	if (pText)
		SetVisible(true);
	else
		SetVisible(false);
}

inline void GuiSelectableText::SetActive(bool bActive)
{
	GuiSelectable::SetActive(bActive);
	UpdateVisual();
}

inline void GuiSelectableText::SetSelectable(bool bSelectable)
{
	GuiSelectable::SetSelectable(bSelectable);
	UpdateVisual();
}

inline void GuiSelectableText::SetHighlightable(bool bHighlightable)
{
	GuiSelectable::SetHighlightable(bHighlightable);
	UpdateVisual();
}

inline void GuiSelectableText::Render( IRenderingEngine * pRenderer )
{
	GuiSelectable::Render( pRenderer );

	if (IsVisible())
		m_TextItem.Render(pRenderer);
}

inline bool GuiSelectableText::OnHighlight(bool bHIghlighted)
{
	bool bSuccess = GuiSelectable::OnHighlight( bHIghlighted );

	UpdateVisual();

	return bSuccess; // bHighlighted
}

inline void GuiSelectableText::UpdateVisual()
{
	if (IsHighlightable())
	{
		if (IsActive())
			m_TextItem.SetColour( CORE::Colour( 255, 255, 255 ) );
		else
			m_TextItem.SetColour( CORE::Colour( 128, 128, 128 ) );
	}
	else
	{
		m_TextItem.SetColour( CORE::Colour( 64, 64, 64 ) );
	}
}

}; // namespace GUI

#endif // _GUI_GuiSelectableText_H_